/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: HelloController
 * Author:   ZX
 * Date:     2020/7/27 17:50
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package org.example.controller;

import org.example.dao.IndexDao;
import org.example.listener.ListenedUser;
import org.example.service.IndexService;
import org.example.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author ZX
 * @create 2020/7/27
 * @since 1.0.0
 */
@RestController
public class HelloController {

    public HelloController(){
        System.out.println("helloController");
    }

    @PostConstruct
    private void init(){
        System.out.println("init method");
    }

    @Autowired
    private IndexService indexService;
    @Autowired
    private PersonService personService;

    @RequestMapping("hello")
    public String hello(String name) {
        return "hello" + name;
    }

    @RequestMapping("hello/user")
    public String helloUser(ListenedUser user, HttpServletRequest request) {
        request.getSession().setAttribute("user", user);
        return "hello" + user.getNickname();
    }

    @RequestMapping("hello/bye")
    public String bye(ListenedUser user, HttpServletRequest request) {
        if (request.getSession(false) != null) {
            request.getSession().invalidate();
        }
        return "bye";
    }

    @RequestMapping("hello/index")
    public String index(){
        System.out.println("helloIndex");
        return indexService.index();
    }
}